package com.py.androidUtils.UI;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;

import com.py.androidUtils.UI.adapter.WeCanSeeAdapter;
import com.py.androidUtils.UI.model.CanSeeView;
import com.py.androidUtils.base.BaseListActivity;
import com.py.androidUtils.pulltorefrsh.PullToRefreshBase.Mode;
import com.readyidu.app.R;

public class WeCanSeeActivity extends BaseListActivity<CanSeeView> {
	private String type = "公开";

	@Override
	public void onActivityCreatedCallBack() {
		commAdapter = new WeCanSeeAdapter(WeCanSeeActivity.this);
		getTitleActionBar().setImgLeft(R.drawable.icon_back, new OnClickListener() {
			@Override
			public void onClick(View v) {
				finishactivity(WeCanSeeActivity.this);
			}
		});
		getTitleActionBar().setTitleBar("");
		getTitleActionBar().setTvRight1("确定", new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = getIntent();
				intent.putExtra("type", type);
				setResult(RESULT_OK, intent);
				finishactivity(WeCanSeeActivity.this);
			}
		});
	}

	@Override
	public void doInbackgroundCallBack() {
		List<CanSeeView> list = new ArrayList<CanSeeView>();
		CanSeeView canSeeView = new CanSeeView();
		canSeeView.setTitle("公开");
		canSeeView.setContent("所有朋友可见");
		canSeeView.setSelect(true);
		canSeeView.setType(1);
		list.add(canSeeView);

		CanSeeView canSeeView1 = new CanSeeView();
		canSeeView1.setTitle("私密");
		canSeeView1.setContent("仅自己可见");
		canSeeView1.setSelect(false);
		canSeeView1.setType(1);
		list.add(canSeeView1);

		CanSeeView canSeeView2 = new CanSeeView();
		canSeeView2.setTitle("部分可见");
		canSeeView2.setContent("选中朋友可见");
		canSeeView2.setSelect(false);
		canSeeView2.setType(0);
		list.add(canSeeView2);

		CanSeeView canSeeView3 = new CanSeeView();
		canSeeView3.setTitle("不给谁看");
		canSeeView3.setContent("选中朋友可见");
		canSeeView3.setSelect(false);
		canSeeView3.setType(0);
		list.add(canSeeView3);

		baseAction.update(list);
	}

	@Override
	public void onPreExecuteCallBack() {

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CanSeeView> doHandelData(Object object) {
		List<CanSeeView> list = (List<CanSeeView>) object;
		return list;
	}

	@Override
	public void onItemClickCallBack(AdapterView<?> parent, View view, int position, long id) {
		for (int i = 0; i < commAdapter.getListData().size(); i++) {
			((CanSeeView) commAdapter.getListData().get(i)).setSelect(false);
		}
		((CanSeeView) commAdapter.getListData().get(position)).setSelect(true);
		commAdapter.notifyDataSetChanged();
		type = ((CanSeeView) commAdapter.getListData().get(position)).getTitle();
		if (((CanSeeView) commAdapter.getListData().get(position)).getType() == 0) {

		}
	}

	@Override
	public View getHeadView() {
		return null;
	}

	@Override
	public View getFooterView() {
		return null;
	}

	@Override
	public Mode getListViewMode() {
		return DISABLED;
	}
}
